package logic

import (
	"context"
	"wxapi/internal/services"

	"wxapi/internal/svc"
	"wxapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSwiperLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetSwiperLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSwiperLogic {
	return &GetSwiperLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetSwiperLogic) GetSwiper() (resp *types.GetIndexSwiperResp, err error) {
	advList, err := services.GetAdvListByPosition(l.ctx, l.svcCtx, 2, 0, 100)
	if err != nil {
		return nil, err
	}

	resp = &types.GetIndexSwiperResp{
		Adv: make([]types.SwiperAdv, 0, len(advList)),
	}
	for _, adv := range advList {
		resp.Adv = append(resp.Adv, types.SwiperAdv{
			Id:             adv.ID,
			Title:          adv.AdvName,
			Avatar:         adv.AdvAvatar,
			RedirectType:   adv.AdvRedirectType,
			RedirectTarget: adv.AdvRedirectTarget,
		})
	}
	return
}
